
/* GCSx
** LAYERLIST.H
**
** Listbox for layer selection
*/

/*****************************************************************************
** Copyright (C) 2003-2006 Janson
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

#ifndef __GCSx_LAYERLIST_H_
#define __GCSx_LAYERLIST_H_

// Uses ListEntry class for items-
//  code1 = flags (visible, dimmed, editable, sprites, etc.)
//  code2 = layer type

class WLayerListBox : public WListBox {
public:
    // Flags used in ListEntry class
    enum {
        FLAG_VISIBLE = 1,
        FLAG_DIMMED = 2,
        FLAG_EDITABLE = 4,
        FLAG_SPRITES_VISIBLE = 8,
        FLAG_SPRITES_DIMMED = 16,
    };

protected:
    // Widgets used
    static const std::string wtLayerVisible;
    static const std::string wtLayerEditable;
    static const std::string wtLayerSprites;
    static const std::string wtLayerTile;
    static const std::string wtLayerFont;
    static const std::string wtLayerImage;
    
    // Position of icon columns and text (last item is text label)
    int iconPos[5];
    int yAddIcon;
    int yAddText;
    
    // Our scene
    class SceneEdit* scene;

    void selectItem(int id, int select = 1, int alone = 1);
    void dblClickItem(int id);
    void rtClickItem(int id);
    void delClickItem(int id);

public:
    // Width in pixels, lines to show vertically
    // Allows exactly one selection, stores id
    WLayerListBox(int lId, int* lSelection, int lWidth = -1, int lLines = -1);
    ~WLayerListBox();
    
    // Which scene to send move/delete notifications to
    void setScene(class SceneEdit* lScene);
    
    // Scans code1 to determine which layers are visible, dimmed, affected
    // Returns as bitmasks- first in list 1, second 2, 4, 8, etc.
    void determineBitMasks(Uint32& layersView, Uint32& layersDim, Uint32& layersAffect) const;
    // Updates layers to match the given layersAffect/etc (doesn't call siblingModified)
    void setBitMask(Uint32 layersAffect, Uint32 layersView, Uint32 layersDim, int selectedLayer = -1);

    // (add/swap doesn't call siblingModified unless selectIt is true)
    // (remove doesn't call siblingModified unless selection changes)
    void addItem(const ListEntry& item, int selectIt = 0);
    void addItem(int position, const ListEntry& item, int selectIt = 0);
    void swapItems(int pos1, int pos2);
    void removeItem(int position);
    void display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset);
    int event(int hasFocus, const SDL_Event* event);
};

#endif

